<template>
  <div id="centerRight1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span>
          <icon name="chart-line" class="text-icon"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2" style="font-size: 16px;">能源类型销售榜</span>
          <span @click="setFlag(0);changeData()" :class="{font_color:flag===0}">油车</span>/
          <span @click="setFlag(1);changeData()" :class="{font_color:flag===1}">电车</span>/
          <span @click="setFlag(2);changeData()" :class="{font_color:flag===2}">其他</span>
        </div>
      </div>
      <div class="d-flex jc-center body-box">
        <dv-scroll-board class="dv-scr-board" :config="config" style="width: 100%;" @mouseover="showData" 
        :title="title"/>
      </div>
    </div>
  </div>
</template>

<script>
import http from '../axios/http';
export default {
  data() {
    return {
      you_list: [],
      dian_list: [],
      other_list: [],
      flag: 0,
      title: "",
      config: {
        header: ['汽车', '销量', '类型'],
        data: [

        ],
        rowNum: 7, //表格行数
        headerHeight: 35,
        headerBGC: '#0f1325', //表头
        oddRowBGC: '#0f1325', //奇数行
        evenRowBGC: '#171c33', //偶数行
        index: true,
        columnWidth: [40],
        align: ['center']
      }
    }
  },
  created () {
    this.get_allData();
    // this.changeData();
  },
  mounted () {
  },
  methods:{
    showData(config){ // 轮播图自带方法 , @mouseover 鼠标悬停时触发动作
      // console.log(config.row[1],config.row[2],config.row[3])
      this.title = config.row[1] + '  ' + config.row[2] + '  ' + config.row[3]
    },
    get_allData(){
        http.get('/largescreen/centerrightone/').then(response=>{
          this.you_list = response.data.you_list
          this.dian_list = response.data.dian_list
          this.other_list = response.data.other_list
          // this.you_list = response.data.you_list
          this.config = {
            header: ['汽车', '销量', '类型'],
            data: response.data.you_list,
            rowNum: 7, //表格行数
            headerHeight: 35,
            headerBGC: '#0f1325', //表头
            oddRowBGC: '#0f1325', //奇数行
            evenRowBGC: '#171c33', //偶数行
            index: true,
            columnWidth: [45,95,75],
            align: ['center']
          }
        }).catch((error)=>{
          console.log(error)
        })
        
    },
    // async changeData(){
    //   const d = await this.get_allData()
    //   this.list = d.you_list
    //   console.log(d.dian_list)
    //   this.config = {
    //     header: ['汽车', '销量', '类型'],
    //     data: d.you_list,
    //     rowNum: 7, //表格行数
    //     headerHeight: 35,
    //     headerBGC: '#0f1325', //表头
    //     oddRowBGC: '#0f1325', //奇数行
    //     evenRowBGC: '#171c33', //偶数行
    //     index: true,
    //     columnWidth: [45,95,75],
    //     align: ['center']
    //   }
    // },
    setFlag(x){
      this.flag = x
    },
    changeData(){
      if (this.flag===0) {
        this.config = {
          header: ['汽车', '销量', '类型'],
          data: this.you_list,
          rowNum: 7, //表格行数
          headerHeight: 35,
          headerBGC: '#0f1325', //表头
          oddRowBGC: '#0f1325', //奇数行
          evenRowBGC: '#171c33', //偶数行
          index: true,
          columnWidth: [45,80,60],
          align: ['center']
        }
      }
      if (this.flag===1) {
        this.config = {
          header: ['汽车', '销量', '类型'],
          data: this.dian_list,
          rowNum: 7, //表格行数
          headerHeight: 35,
          headerBGC: '#0f1325', //表头
          oddRowBGC: '#0f1325', //奇数行
          evenRowBGC: '#171c33', //偶数行
          index: true,
          columnWidth: [45,80,60],
          align: ['center']
        }
      }
      if (this.flag===2) {
        this.config = {
          header: ['汽车', '销量', '类型'],
          data: this.other_list,
          rowNum: 7, //表格行数
          headerHeight: 35,
          headerBGC: '#0f1325', //表头
          oddRowBGC: '#0f1325', //奇数行
          evenRowBGC: '#171c33', //偶数行
          index: true,
          columnWidth: [45,80,60],
          align: ['center']
        }
      }
    },
  },
}
</script>

<style lang="scss" scoped>
$box-height: 410px;
$box-width: 310px;
#centerRight1 {
  padding: 16px;
  padding-top: 20px;
  height: $box-height;
  width: $box-width;
  border-radius: 5px;
  .bg-color-black {
    height: $box-height - 30px;
    border-radius: 10px;
  }
  .text {
    color: #c3cbde;
  }
  .body-box {
    border-radius: 10px;
    overflow: hidden;
    .dv-scr-board {
      width: 270px;
      height: 340px;
    }
  }
  .font_color {
    color: rgb(83, 83, 253);
  }
}
</style>
